package model.daos;

import java.util.Iterator;
import java.util.List;

import model.db.DataBase;
import model.dtos.Game;

public class GameDao implements GenericDao<Game>
{

	@Override
	public void save(Game dt)
	{
		DataBase.getSeason().getGames().add(dt);
	}

	@Override
	public Game findById(String id)
	{
		Game game = null;
		
		for (Game g : DataBase.getSeason().getGames())
		{
			if (g.getCode().equals(id))
			{
				game = g;
				break;
			}
		}
		
		return game;
	}

	@Override
	public List<Game> findAll()
	{
		return DataBase.getSeason().getGames();
	}

	@Override
	public void deleteById(String id)
	{
		Iterator<Game> it = DataBase.getSeason().getGames().iterator();

		while (it.hasNext())
		{
			if (it.next().getCode().equals(id))
			{
				it.remove();
				break;
			}
		}
	}

	@Override
	public void deleteAll()
	{
			DataBase.getSeason().getGames().clear();
	}

}
